namespace SimpleFactory.FactoryMethod
{
    /*
     * 为了解决客户端还是要依赖具体的问题，加入DI
     */
    public class Assembler
    {
        //? 保存‘抽象类型/实体类型’的对应关系
        private static Dictionary<Type, Type> _dictionary = new Dictionary<Type, Type>();

        static Assembler()
        {
            _dictionary.Add(typeof(IProduct), typeof(ProductA));
        }

        public object Create(Type type)
        {
            if ((type == null) || !_dictionary.ContainsKey(type))
                throw new NullReferenceException();
            Type targetType = _dictionary[type];
            return new FactoryA().Create();
        }

        public T Create<T>()
        {
            return (T)Create(typeof(T));
        }
    }
}